
/*
 * The AP_NoFlyZone library:
 * 
 * 
 * - responsible for managing a list of no_fly_zone points
 * - reads and writes the no_fly_zone points to storage
 * - provides access to the no_fly_zone points, including logic to find the nearest one
 *
 */

#ifndef AP_NoFlyZone_h
#define AP_NoFlyZone_h

#include <AP_Common/AP_Common.h>
#include <AP_Param/AP_Param.h>
#include <AP_Flash/flash_stm32.h>

#define AP_NOFLYZONE_WP_SIZE        8  // flash size of no_fly_zone points


struct PACKED NoFlyZoneLocation {
	float lat; /*< Latitude of point*/
 	float lng; /*< Longitude of point*/
};


/// @class    AP_Rally
/// @brief    Object managing Rally Points
class AP_NoFlyZone{
	public:
    AP_NoFlyZone();

    // data handling
    bool get_noflyzone_point_with_index(uint16_t i, NoFlyZoneLocation &ret) const;
    bool set_noflyzone_point_with_index(uint16_t i, const NoFlyZoneLocation &noflyzoneloc);
    uint16_t get_noflyzone_total() const { return _noflyzone_point_total_count; }
    uint16_t get_noflyzone_max(void) const { return (uint16_t)(Flash_available_size() / AP_NOFLYZONE_WP_SIZE); }

    
    bool find_nearest_noflyzone_point(const Location &myloc, RallyLocation &ret) const;

    // last time rally points changed
    uint32_t last_change_time_ms(void) const { return _last_change_time_ms; }

    // parameter block
    static const struct AP_Param::GroupInfo var_info[];

private:
	
    // parameters
    AP_Int16  _noflyzone_point_total_count;

    uint32_t _last_change_time_ms;
};


#endif // AP_NoFlyZone_h